home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 60 / IOPROG_60.ISO / soft / c++ / gsl-1.1.1-setup.exe / {app} / src / sys / infnan.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-04-18  |  2.0 KB  |  105 lines

  1. /* sys/infnan.c
  2.  * 
  3.  * Copyright (C) 2001 Brian Gough
  4.  * 
  5.  * This program is free software; you can redistribute it and/or modify
  6.  * it under the terms of the GNU General Public License as published by
  7.  * the Free Software Foundation; either version 2 of the License, or (at
  8.  * your option) any later version.
  9.  * 
  10.  * This program is distributed in the hope that it will be useful, but
  11.  * WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.  * General Public License for more details.
  14.  * 
  15.  * You should have received a copy of the GNU General Public License
  16.  * along with this program; if not, write to the Free Software
  17.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  */
  19.  
  20. #include <config.h>
  21. #include <math.h>
  22.  
  23. double gsl_nan (void);
  24. double gsl_posinf (void);
  25. double gsl_neginf (void);
  26. double gsl_fdiv (const double x, const double y);
  27.  
  28. double gsl_nan (void)
  29. {
  30.   return gsl_fdiv (0.0, 0.0);
  31. }
  32.  
  33. double gsl_posinf (void)
  34. {
  35.   return gsl_fdiv (+1.0, 0.0);
  36. }
  37.  
  38. double gsl_neginf (void)
  39. {
  40.   return gsl_fdiv (-1.0, 0.0);
  41. }
  42.  
  43.  
  44. int gsl_isnan (const double x);
  45. int gsl_isinf (const double x);
  46. int gsl_finite (const double x);
  47.  
  48. #if defined(_MSC_VER) /* Microsoft Visual C++ */
  49. #include <float.h>
  50. int
  51. gsl_isnan (const double x)
  52. {
  53.   return _isnan(x);
  54. }
  55.  
  56. int
  57. gsl_isinf (const double x)
  58. {
  59.   int fpc = _fpclass(x);
  60.  
  61.   if (fpc == _FPCLASS_PINF)
  62.     return +1;
  63.   else if (fpc == _FPCLASS_NINF)
  64.     return -1;
  65.   else 
  66.     return 0;
  67. }
  68.  
  69. int
  70. gsl_finite (const double x)
  71. {
  72.   return _finite(x);
  73. }
  74. #elif defined(HAVE_IEEE_COMPARISONS)
  75. int
  76. gsl_isnan (const double x)
  77. {
  78.   int status = (x != x);
  79.   return status;
  80. }
  81.  
  82. int
  83. gsl_isinf (const double x)
  84. {
  85.   double y = x - x;
  86.   int s = (y != y);
  87.  
  88.   if (s && x > 0)
  89.     return +1;
  90.   else if (s && x < 0)
  91.     return -1;
  92.   else
  93.     return 0;
  94. }
  95.  
  96. int
  97. gsl_finite (const double x)
  98. {
  99.   const double y = x - x;
  100.   int status = (y == y);
  101.   return status;
  102. }
  103. #endif
  104.  
  105.